<?php 
include("conn.php");
?>
<style>
.fset{width:130px;}
.fset2{width:114px;}
</style>
<script src="plugins/enq/assets/jscolor.js" type="text/javascript"></script>
<script src="plugins/enq/assets/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function createXMLHttp() {
 var xmlhttp = false; 
 try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
 catch (e){
  try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (E){xmlhttp = false; }
 }
 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  xmlhttp = new XMLHttpRequest(); 
 }
 return xmlhttp; 
}

function getRequestBody(oForm){
 var aParams = new Array(); 
 for (var i=0 ; i < oForm.elements.length; i++) {
  var sParam = encodeURIComponent(oForm.elements[i].name); 
  sParam += "="; 
  sParam += encodeURIComponent(oForm.elements[i].value); 
  aParams.push(sParam); 
 }
 return aParams.join("&"); 
}
function sendPostRequest() {
 var oForm = document.forms[0]; 
 var sBody = getRequestBody(oForm); 
 var xmlhttp = createXMLHttp(); 
 xmlhttp.open("POST", "plugins/enq/function.php", true); 
 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
 xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState == 4) {
   if (xmlhttp.status == 200) {
//    alert("Updated successfully!");
   } else {
//    alert("Failed!");
   }
  }
 }; 
 xmlhttp.send(sBody); 
}

function checkboxValue(obj) { 
 if(obj.checked) { 
  obj.value = '1'; 
 } else {
  obj.value = '0';
   }
} 
</script>
 <form action="" onsubmit="sendPostRequest(); return false;" style="margin: 50px 0;">
   <div style="display: none"><input value = <?php echo($instance_id) ?> name="instance" /></div>
   <div style="width:600px;">
   <table style="width:100%;text-align: center;border:solid 1px #ccc;border-bottom:none;" cellSpacing="3" id="enq_<?php echo $instance_id?>_maintable">
     <tr>
      <td style="display: none;"></td>
      <td style="font-weight:bold;height:22px;color:#555;">Name</td>
      <td style="font-weight:bold;height:22px;color:#555;">Type</td>
      <td style="font-weight:bold;height:22px;color:#555;">With</td>
      <td style="font-weight:bold;height:22px;color:#555;">Height</td>
      <td style="font-weight:bold;height:22px;color:#555;">Nessary</td>
      <td style="font-weight:bold;height:22px;color:#555;">Delete</td>
    </tr>
    <?php 
    foreach ($result1 as &$row) {
     ?>
   <tr>
     <td style="display: none;"><input name="m_id[]" value=<?php  echo $row->id ?> /></td>
     <td><input value=<?php  echo $row->title ?> name="title[]" style="width:150px;" /></td>
     <td><select name="select[]" style="width:100px; height:21px;" >
           <option <?php if($row->input_type == 'Text') echo ("selected"); ?>>Text</option>
           <option <?php if($row->input_type == 'TextArea') echo ("selected"); ?>>TextArea</option>
         </select>
     </td>
     <td><input value=<?php  echo $row->width ?> name="width[]" style="width:50px;" />px </td>
     <td><input value=<?php  echo $row->height ?> name="height[]" style="width:50px;"/>px </td>
     <td><input type="checkbox" name="nessary[]" onclick="checkboxValue(this);" <?php if($row->nessary == '1') echo ("checked value='1' "); else echo("value='0'"); ?> ></input></td>
     <td><input type="button" style="font-size:11px;width:50px;" value="Delete" onclick="deleteRow(this)"></td>
   </tr>
   <?php
   }
   ?>
   </table>
   <div style="padding: 5px 0 5px 13px;text-align:left;border:solid 1px #ccc;border-top:none;"><a style="cursor:pointer;text-decoration:underline;" onclick="insertRow(-1)" >Add a row</a></div>
   
   <div style="height:18px;padding: 5px 0;background:#ccc;margin-top:5px;" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_eset">
     <div style="float:left;width:18px;margin:0 5px;height:18px;background-image:url(plugins/enq/assets/plusminus.png);background-position:0 0;" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_emore"></div>
     <div style="float:left;font-weight: bold;font-size:15px;color:#fff;">邮件配置</div>
   </div>
   <div style="border: solid 1px #ccc;padding: 10px 23px;" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_ediv">
     <div style="display: none;"><input name="e_id" value=<?php  echo $e_id ?> /></div>
     <table cellpadding=3 cellspacing=0>
       <tr><td class="fset">收件人地址</td><td><input style="width: 300px;" value="<?php if($to){echo $to;} else{ echo '';}?>" name="email"></td></tr>
       <tr><td class="fset">收件人称呼</td><td><input style="width: 300px;" value="<?php echo $recepter_name?>" name="recepter_name"></td></tr>
       <tr><td class="fset">邮件主题</td><td><input style="width: 300px;" value="<?php echo $subject?>" name="subject"></td></tr>
       <tr><td class="fset">发件人地址</td><td><input style="width: 300px;" value="<?php echo $mail_from?>" name="mail_from"></td></tr>
       <tr><td class="fset">发件人称呼</td><td><input style="width: 300px;" value="<?php echo $sender_name?>" name="sender_name"></td></tr>
       <tr><td class="fset">安全协议</td><td><input style="width: 300px;" value="<?php echo $smtp_secure?>" name="smtp_secure"></td></tr>
       <tr><td class="fset">SMTP 服务器</td><td><input style="width: 300px;" value="<?php echo $host?>" name="host"></td></tr>
       <tr><td class="fset">SMTP 服务器端口号</td><td><input style="width: 300px;" value="<?php echo $port?>" name="port"></td></tr>
       <tr><td class="fset">SMTP 服务器用户名</td><td><input style="width: 300px;" value="<?php echo $username?>" name="username"></td></tr>
       <tr><td class="fset">SMTP 服务器密码</td><td><input type="password" style="width: 300px;" value="<?php echo $password?>" name="password"></td></tr>
     </table>
   </div>
   
   <div style="height:18px;padding: 5px 0;background:#ccc;margin-top:5px;" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_fset">
     <div style="float:left;width:18px;margin:0 5px;height:18px;background-image:url(plugins/enq/assets/plusminus.png);background-position:0 0;" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_fmore"></div>
     <div style="float:left;font-weight: bold;font-size:15px;color:#fff;">样式设置</div>
   </div>
   <div style="border: solid 1px #ccc;padding: 10px 0 10px 23px;" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_fdiv">
     <table cellpadding=3 cellspacing=0>
       <tr><td class="fset">表格背景颜色</td><td><input class="color" style="width: 300px;" value="<?php echo $f_bgcolor?>" name="f_bgcolor" id="f_bgcolor" <?php if($f_bgcolor_tran == 1){echo("disabled='disabled'");} ?> >
                                                <input type="checkbox" name="f_bgcolor_tran" <?php if($f_bgcolor_tran == 1){echo("checked value='1'");}else{echo("value='0'");} ?> onclick="if (f_bgcolor.disabled==false){f_bgcolor.disabled=true;this.value='1'} else {f_bgcolor.disabled=false;this.value='0'}">透明</input></td></tr>
       <tr><td class="fset">字体颜色</td><td><input class="color" style="width: 300px;" value="<?php echo $f_color?>" name="f_color"></td></tr>
       <tr><td class="fset">输入框边框颜色</td><td><input class="color" style="width: 300px;" value="<?php echo $text_border?>" name="text_border"></td></tr>
       <tr><td class="fset">字体</td><td>
       <select name="f_font" style="width:304px; height:21px;" >
           <option <?php if($f_font == 'Andale Mono') echo ("selected"); ?>>Andale Mono</option>
           <option <?php if($f_font == 'Arial') echo ("selected"); ?>>Arial</option>
           <option <?php if($f_font == 'Arial Black') echo ("selected"); ?>>Arial Black</option>
           <option <?php if($f_font == 'Book Antiqua') echo ("selected"); ?>>Book Antiqua</option>
           <option <?php if($f_font == 'Comic Sans MS') echo ("selected"); ?>>Comic Sans MS</option>
           <option <?php if($f_font == 'Courier New') echo ("selected"); ?>>Courier New</option>
           <option <?php if($f_font == 'Courier') echo ("selected"); ?>>Courier</option>
           <option <?php if($f_font == 'Georgia') echo ("selected"); ?>>Georgia</option>
           <option <?php if($f_font == 'Helvetica') echo ("selected"); ?>>Helvetica</option>
           <option <?php if($f_font == 'Impact') echo ("selected"); ?>>Impact</option>
           <option <?php if($f_font == 'Symbol') echo ("selected"); ?>>Symbol</option>
           <option <?php if($f_font == 'Tahoma') echo ("selected"); ?>>Tahoma</option>
           <option <?php if($f_font == 'Terminal') echo ("selected"); ?>>Terminal</option>
           <option <?php if($f_font == 'Times New Roman') echo ("selected"); ?>>Times New Roman</option>
           <option <?php if($f_font == 'Trebuchet MS') echo ("selected"); ?>>Trebuchet MS</option>
           <option <?php if($f_font == 'Verdana') echo ("selected"); ?>>Verdana</option>
           <option <?php if($f_font == 'Webdings') echo ("selected"); ?>>Webdings</option>
           <option <?php if($f_font == 'Wingdings') echo ("selected"); ?>>Wingdings</option>
         </select>
       </td></tr>
       <tr><td class="fset">字体大小</td><td><input style="width: 300px;" value="<?php echo $f_size?>" name="f_size"></td></tr>
       <tr><td class="fset">字体粗细</td><td>
         <select name="f_weight" style="width:304px; height:21px;" >
           <option <?php if($f_weight == 'Normal') echo ("selected"); ?>>Normal</option>
           <option <?php if($f_weight == 'Bold') echo ("selected"); ?>>Bold</option>
         </select>
       </td></tr>
       <tr><td class="fset">表格内间距</td><td><input style="width: 300px;" value="<?php echo $cellpadding?>" name="cellpadding"></td></tr>
     </table>
   <div style="height:18px;padding: 2px 0;background:#ccc;margin-top:5px;" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_bset">
     <div style="float:left;width:18px;margin:0 2px;height:18px;background-image:url(plugins/enq/assets/plusminus.png);background-position:0 0;" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_bmore"></div>
     <div style="float:left;font-weight: bold;font-size:15px;color:#fff;">发送按钮设置</div>
   </div>
   <div style="border: solid 1px #ccc;border-right:none;padding: 10px 25px;" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_bdiv">
     <table cellpadding=3 cellspacing=0>
       <tr><td class="fset2">按钮文字</td><td><input style="width: 300px;" value="<?php echo $b_text?>" name="b_text"></td></tr>
       <tr><td class="fset2">按钮宽度</td><td><input style="width: 300px;" value="<?php echo $b_width?>" name="b_width"></td></tr>
       <tr><td class="fset2">按钮高度</td><td><input style="width: 300px;" value="<?php echo $b_height?>" name="b_height"></td></tr>
       <tr><td class="fset2">背景颜色</td><td><input class="color" style="width: 300px;" value="<?php echo $b_bgcolor?>" name="b_bgcolor"></td></tr>
       <tr><td class="fset2">字体颜色</td><td><input class="color" style="width: 300px;" value="<?php echo $b_color?>" name="b_color"></td></tr>
       <tr><td class="fset2">字体</td><td>
         <select name="b_font" style="width:304px; height:21px;" >
             <option <?php if($b_font == 'Andale Mono') echo ("selected"); ?>>Andale Mono</option>
             <option <?php if($b_font == 'Arial') echo ("selected"); ?>>Arial</option>
             <option <?php if($b_font == 'Arial Black') echo ("selected"); ?>>Arial Black</option>
             <option <?php if($b_font == 'Book Antiqua') echo ("selected"); ?>>Book Antiqua</option>
             <option <?php if($b_font == 'Comic Sans MS') echo ("selected"); ?>>Comic Sans MS</option>
             <option <?php if($b_font == 'Courier New') echo ("selected"); ?>>Courier New</option>
             <option <?php if($b_font == 'Courier') echo ("selected"); ?>>Courier</option>
             <option <?php if($b_font == 'Georgia') echo ("selected"); ?>>Georgia</option>
             <option <?php if($b_font == 'Helvetica') echo ("selected"); ?>>Helvetica</option>
             <option <?php if($b_font == 'Impact') echo ("selected"); ?>>Impact</option>
             <option <?php if($b_font == 'Symbol') echo ("selected"); ?>>Symbol</option>
             <option <?php if($b_font == 'Tahoma') echo ("selected"); ?>>Tahoma</option>
             <option <?php if($b_font == 'Terminal') echo ("selected"); ?>>Terminal</option>
             <option <?php if($b_font == 'Times New Roman') echo ("selected"); ?>>Times New Roman</option>
             <option <?php if($b_font == 'Trebuchet MS') echo ("selected"); ?>>Trebuchet MS</option>
             <option <?php if($b_font == 'Verdana') echo ("selected"); ?>>Verdana</option>
             <option <?php if($b_font == 'Webdings') echo ("selected"); ?>>Webdings</option>
             <option <?php if($b_font == 'Wingdings') echo ("selected"); ?>>Wingdings</option>
           </select>
       </td></tr>
       <tr><td class="fset">字体大小</td><td><input style="width: 300px;" value="<?php echo $b_size?>" name="b_size"></td></tr>
       <tr><td class="fset">字体粗细</td><td>
         <select name="b_weight" style="width:304px; height:21px;" >
           <option <?php if($f_weight == 'Normal') echo ("selected"); ?>>Normal</option>
           <option <?php if($f_weight == 'Bold') echo ("selected"); ?>>Bold</option>
         </select>
       </td></tr>
     </table>
   </div>
   </div>
   
   
   <div style="text-align:right;"><input type="submit" id="<?php echo $this->folder ?>_<?php echo $instance_id?>_save" value="Save"></div>
   </div>
</form>

<script type="text/javascript">
var tr, td;
var main = document.getElementById('<?php echo $this->folder ?>_<?php echo $instance_id?>_maintable');
function insertRow(iPos){
  tr=main.insertRow(iPos);
  td=tr.insertCell(-1);
  td.style.display = 'none';
  td.innerHTML="<input type=text name='m_id[]' style='width:150px;' />";
  td=tr.insertCell(-1);
  td.innerHTML="<input type=text name='title[]' style='width:150px;' />";
  td=tr.insertCell(-1);
  td.innerHTML="<select name='select[]' style='width:100px; height:21px;'><option>Text</option><option>TextArea</option></seelct>";
  td=tr.insertCell(-1);
  td.innerHTML="<input type=text name='width[]' value='250' style='width:50px;' />px ";
  td=tr.insertCell(-1);
  td.innerHTML="<input type=text name='height[]' value='16' style='width:50px;' />px ";
  td=tr.insertCell(-1);
  td.innerHTML="<input type=checkbox name='nessary[]' value='0' onclick='checkboxValue(this);'/>";
  td=tr.insertCell(-1);
  td.innerHTML=" <input type=button style='font-size:11px;width:50px;' onclick='deleteRow(this)' value='Delete'>";
}
function deleteRow(r) {
  var i=r.parentNode.parentNode.rowIndex;
  main.deleteRow(i);
}

function checkboxTran() { 
  if (f_bgcolor.disabled==false){f_bgcolor.disabled=true;this.value='1'} else {f_bgcolor.disabled=false;this.value='0'}
} 

$('#<?php echo $this->folder ?>_<?php echo $instance_id?>_eset').toggle(
  function(){
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_emore').css('backgroundPosition','0 -18px');
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_ediv').slideDown("slow");
  },
  function(){
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_emore').css('backgroundPosition','0 0');
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_ediv').slideUp("slow");
  }
);

$('#<?php echo $this->folder ?>_<?php echo $instance_id?>_fset').toggle(
  function(){
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_fmore').css('backgroundPosition','0 -18px');
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_fdiv').slideDown("slow");
  },
  function(){
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_fmore').css('backgroundPosition','0 0');
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_fdiv').slideUp("slow");
  }
);

$('#<?php echo $this->folder ?>_<?php echo $instance_id?>_bset').toggle(
  function(){
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_bmore').css('backgroundPosition','0 -18px');
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_bdiv').slideDown("slow");
  },
  function(){
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_bmore').css('backgroundPosition','0 0');
    $('#<?php echo $this->folder ?>_<?php echo $instance_id?>_bdiv').slideUp("slow");
  }
);


</script>
<br />
<br />
<br />
